﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Presentation.Commands;
using StockholmsStad.Runtime.Serialization.DataContract;

namespace StockholmsStad.Windows.UI.Modules.Maintenance.Models
{
    public class CeremonyValuesPresentationModel : INotifyPropertyChanged
    {
        public event EventHandler<DataEventArgs<CeremonyValuesPresentationModel>> Saved;
        public event EventHandler<DataEventArgs<CeremonyValuesPresentationModel>> AddedLanguage;
        public event EventHandler<DataEventArgs<CeremonyValuesPresentationModel>> ChangedLanguage;
        public event EventHandler<DataEventArgs<CeremonyValuesPresentationModel>> DeletedLanguage;
        public event EventHandler<DataEventArgs<CeremonyValuesPresentationModel>> AddedSpecialNeed;
        public event EventHandler<DataEventArgs<CeremonyValuesPresentationModel>> AddedCeremonyLanguage;
        public event EventHandler<DataEventArgs<CeremonyValuesPresentationModel>> DeletedCeremonyLanguage;
        public event EventHandler<DataEventArgs<CeremonyValuesPresentationModel>> AddedCertificateLanguage;
        public event EventHandler<DataEventArgs<CeremonyValuesPresentationModel>> DeletedCertificateLanguage;
        public DelegateCommand<object> SaveCommand { get; private set; }
        public DelegateCommand<object> AddLanguageCommand { get; private set; }
        public DelegateCommand<object> ChangeLanguageCommand { get; private set; }
        public DelegateCommand<object> DeleteLanguageCommand { get; private set; }
        public DelegateCommand<object> AddSpecialNeedCommand { get; private set; }
        public DelegateCommand<object> AddCeremonyLanguageCommand { get; private set; }
        public DelegateCommand<object> DeleteCeremonyLanguageCommand { get; private set; }
        public DelegateCommand<object> AddCertificateLanguageCommand { get; private set; }
        public DelegateCommand<object> DeleteCertificateLanguageCommand { get; private set; }

        public CeremonyValuesPresentationModel()
        {
            SaveCommand = new DelegateCommand<object>(Save);
            AddLanguageCommand = new DelegateCommand<object>(AddLanguage);
            ChangeLanguageCommand = new DelegateCommand<object>(ChangeLanguage);
            DeleteLanguageCommand = new DelegateCommand<object>(DeleteLanguage);
            AddSpecialNeedCommand = new DelegateCommand<object>(AddSpecialNeed);
            AddCeremonyLanguageCommand = new DelegateCommand<object>(AddCeremonyLanguage);
            DeleteCeremonyLanguageCommand = new DelegateCommand<object>(DeleteCeremonyLanguage);
            AddCertificateLanguageCommand = new DelegateCommand<object>(AddCertificateLanguage);
            DeleteCertificateLanguageCommand = new DelegateCommand<object>(DeleteCertificateLanguage);

            PropertyChanged += OnPropertyChangedEvent;
        }

        #region Properties

        public string HeaderInfo
        {
            get { return HeaderNames.CeremonySettings; }
        }

        private ValueIdPair newCeremonyLanguage;
        public ValueIdPair NewCeremonyLanguage
        {
            get
            {
                return newCeremonyLanguage;
            }
            set
            {
                if (!value.Equals(newCeremonyLanguage))
                {
                    newCeremonyLanguage = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("NewCeremonyLanguage"));
                }
            }
        }

        private ValueIdPair newCertificateLanguage;
        public ValueIdPair NewCertificateLanguage
        {
            get
            {
                return newCertificateLanguage;
            }
            set
            {
                if (!value.Equals(newCertificateLanguage))
                {
                    newCertificateLanguage = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("NewCertificateLanguage"));
                }
            }
        }

        private ValueIdPair newSpecialNeed;
        public ValueIdPair NewSpecialNeed
        {
            get
            {
                return newSpecialNeed;
            }
            set
            {
                if (!value.Equals(newSpecialNeed))
                {
                    newSpecialNeed = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("NewSpecialNeed"));
                }
            }
        }

        private ValueIdPair newLanguage;
        public ValueIdPair NewLanguage
        {
            get
            {
                return newLanguage;
            }
            set
            {
                if (!value.Equals(newLanguage))
                {
                    newLanguage = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("NewLanguage"));
                }
            }
        }

        private ObservableCollection<ValueIdPair> allLanguages;
        public ObservableCollection<ValueIdPair> AllLanguages
        {
            get
            {
                return allLanguages;
            }
            set
            {
                if (!value.Equals(allLanguages))
                {
                    allLanguages = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("AllLanguages"));
                }
            }
        }

        private ObservableCollection<ValueIdPair> ceremonyLanguages;
        public ObservableCollection<ValueIdPair> CeremonyLanguages
        {
            get
            {
                return ceremonyLanguages;
            }
            set
            {
                if (!value.Equals(ceremonyLanguages))
                {
                    ceremonyLanguages = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("CeremonyLanguages"));
                }
            }
        }

        private ObservableCollection<ValueIdPair> certificateLanguages;
        public ObservableCollection<ValueIdPair> CertificateLanguages
        {
            get
            {
                return certificateLanguages;
            }
            set
            {
                if (!value.Equals(certificateLanguages))
                {
                    certificateLanguages = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("CertificateLanguages"));
                }
            }
        }

        private ObservableCollection<ValueIdPair> allReportLanguages;
        public ObservableCollection<ValueIdPair> AllReportLanguages
        {
            get
            {
                return allReportLanguages;
            }
            set
            {
                if (!value.Equals(allReportLanguages))
                {
                    allReportLanguages = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("AllReportLanguages"));
                }
            }
        }

        private ObservableCollection<ValueIdPair> allSpecialNeeds;
        public ObservableCollection<ValueIdPair> AllSpecialNeeds
        {
            get
            {
                return allSpecialNeeds;
            }
            set
            {
                if (!value.Equals(allSpecialNeeds))
                {
                    allSpecialNeeds = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("AllSpecialNeeds"));
                }
            }
        }

        #endregion

        private void OnPropertyChangedEvent(object sender, PropertyChangedEventArgs e)
        {
            //SaveCommand.RaiseCanExecuteChanged();
            //AddLanguageCommand.RaiseCanExecuteChanged();
        }

        private void Save(object obj)
        {
            OnSaved(new DataEventArgs<CeremonyValuesPresentationModel>(this));
        }

        private void AddLanguage(object obj)
        {
            OnAddedLanguage(new DataEventArgs<CeremonyValuesPresentationModel>(this));
        }

        private void ChangeLanguage(object obj)
        {
            OnChangedLanguage(new DataEventArgs<CeremonyValuesPresentationModel>(this));
        }

        private void DeleteLanguage(object obj)
        {
            OnDeletedLanguage(new DataEventArgs<CeremonyValuesPresentationModel>(this));
        }

        private void AddSpecialNeed(object obj)
        {
            OnAddedSpecialNeed(new DataEventArgs<CeremonyValuesPresentationModel>(this));
        }

        private void AddCeremonyLanguage(object obj)
        {
            OnAddedCeremonyLanguage(new DataEventArgs<CeremonyValuesPresentationModel>(this));
        }

        private void DeleteCeremonyLanguage(object obj)
        {
            OnDeleteCeremonyLanguage(new DataEventArgs<CeremonyValuesPresentationModel>(this));
        }

        private void AddCertificateLanguage(object obj)
        {
            OnAddedCertificateLanguage(new DataEventArgs<CeremonyValuesPresentationModel>(this));
        }

        private void DeleteCertificateLanguage(object obj)
        {
            OnDeletedCertificateLanguage(new DataEventArgs<CeremonyValuesPresentationModel>(this));
        }

        private void OnSaved(DataEventArgs<CeremonyValuesPresentationModel> e)
        {
            var savedHandler = Saved;

            if (savedHandler != null)
                savedHandler(this, e);
        }

        private void OnAddedLanguage(DataEventArgs<CeremonyValuesPresentationModel> e)
        {
            var addedLanguageHandler = AddedLanguage;

            if (addedLanguageHandler != null)
                addedLanguageHandler(this, e);
        }

        private void OnChangedLanguage(DataEventArgs<CeremonyValuesPresentationModel> e)
        {
            var changedLanguageHandler = ChangedLanguage;

            if (changedLanguageHandler != null)
                changedLanguageHandler(this, e);
        }

        private void OnDeletedLanguage(DataEventArgs<CeremonyValuesPresentationModel> e)
        {
            var deletedLanguageHandler = DeletedLanguage;

            if (deletedLanguageHandler != null)
                deletedLanguageHandler(this, e);
        }

        private void OnDeleteCeremonyLanguage(DataEventArgs<CeremonyValuesPresentationModel> e)
        {
            var deleteHandler = DeletedCeremonyLanguage;

            if (deleteHandler != null)
                deleteHandler(this, e);
        }

        private void OnAddedSpecialNeed(DataEventArgs<CeremonyValuesPresentationModel> e)
        {
            var addedHandler = AddedSpecialNeed;

            if (addedHandler != null)
                addedHandler(this, e);
        }

        private void OnAddedCeremonyLanguage(DataEventArgs<CeremonyValuesPresentationModel> e)
        {
            var addedHandler = AddedCeremonyLanguage;

            if (addedHandler != null)
                addedHandler(this, e);
        }

        private void OnAddedCertificateLanguage(DataEventArgs<CeremonyValuesPresentationModel> e)
        {
            var addedHandler = AddedCertificateLanguage;

            if (addedHandler != null)
                addedHandler(this, e);
        }

        private void OnDeletedCertificateLanguage(DataEventArgs<CeremonyValuesPresentationModel> e)
        {
            var deleteHandler = DeletedCertificateLanguage;

            if (deleteHandler != null)
                deleteHandler(this, e);
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
